package com.easyexcel.demo.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.easyexcel.demo.component.UserMultiSheetService;
import com.easyexcel.demo.component.UserNoModelService;
import com.easyexcel.demo.result.R;
import com.easyexcel.demo.service.UserService;
import com.easyexcel.demo.vo.UserQuery;
import com.easyexcel.demo.vo.UserVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * zhaoxh
 */
@RestController
@Api(tags = "用户表的导入/导出测试")
@RequestMapping("/user")
public class UserController {

    @Resource
    private UserService userService;

    @Resource
    private UserMultiSheetService userManager;


    @Resource
    private UserNoModelService userNoModelWrite;

    @ApiOperation(value = "分页接口")
    @PostMapping("/page")
    public R<Page<UserVO>> page(@RequestBody UserQuery query) {
        Page<UserVO> page = userService.page(query);
        return R.ok(page);
    }

    @ApiOperation(value = "分批导出-单sheet页")
    @PostMapping("/exportExcel")
    public void exportExcel(HttpServletRequest request, HttpServletResponse response, @RequestBody UserQuery query) {
        userService.exportExcel(request, response, query);
    }

    @ApiOperation(value = "分批导出-多sheet页")
    @PostMapping("/exportExcelV2")
    public void exportExcelV2(HttpServletRequest request, HttpServletResponse response, @RequestBody UserQuery query) {
        userManager.exportExcel(request, response, query);
    }

    @ApiOperation(value = "分批导出-单sheet页-固定模板导出")
    @PostMapping("/exportExcelV3")
    public void exportExcelV3(HttpServletRequest request, HttpServletResponse response, @RequestBody UserQuery query) {
        userService.exportExcelV3(request, response, query);
    }

    @ApiOperation(value = "分批导入-单sheet页-固定模板导入")
    @RequestMapping(value = "/importExcel")
    public R<Boolean>  importExcel(HttpServletRequest request,HttpServletResponse response, @RequestParam MultipartFile file) {
        return R.ok(userService.importExcel(request, response, file));
    }



    @ApiOperation(value = "导出-动态模板列")
    @PostMapping("/exportNoModel")
    public void exportNoModel(HttpServletRequest request, HttpServletResponse response, @RequestBody UserQuery query) {
        userNoModelWrite.exportExcel(request, response,query);
    }

}
